package com.carleasoft.mps.exam.business.questions.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.carleasoft.mps.core.result.R;
import com.carleasoft.mps.core.user.ThreadUserContext;
import com.carleasoft.mps.core.user.UserCacheData;
import com.carleasoft.mps.exam.business.questions.bean.entity.ETopic;
import com.carleasoft.mps.exam.business.questions.bean.po.DownloadPo;
import com.carleasoft.mps.exam.business.questions.bean.po.ETopicAddOrEditPo;
import com.carleasoft.mps.exam.business.questions.bean.po.ETopicPageQueryPo;
import com.carleasoft.mps.exam.business.questions.bean.vo.ETopicVo;
import com.carleasoft.mps.exam.business.questions.service.ETopicService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * <p>
 * 题目主表 前端控制器
 * </p>
 *
 * @author fan
 * @since 2023-05-17
 */
@RestController
@RequestMapping("/eTopic")
public class ETopicController {

    @Autowired
    private ETopicService eTopicService;

    /**
     * 题目-新增
     */
    @PostMapping("/eTopicAdd")
    public R eTopicAdd(@RequestBody ETopicAddOrEditPo eTopicAddOrEditPo){
        return R.ok(eTopicService.eTopicAdd(eTopicAddOrEditPo));
    }
    /**
     * 题目-编辑
     */
    @PostMapping("/eTopicEdit")
    public R eTopicEdit(@RequestBody  ETopicAddOrEditPo eTopicAddOrEditPo){
        return R.ok(eTopicService.eTopicEdit(eTopicAddOrEditPo));
    }
    /**
     * 题目-删除
     */
    @PostMapping("/eTopicDelete")
    public R eTopicDelete(@RequestBody ETopic eTopic){
        return R.ok(eTopicService.eTopicDelete(eTopic));
    }
    /**
     * 题目-分页查询
     */
    @PostMapping("/eTopicPageQuery")
    public R<Page<ETopicVo>> eTopicPageQuery(@RequestBody ETopicPageQueryPo eTopicPageQueryPo){
        return R.ok(eTopicService.eTopicPageQuery(eTopicPageQueryPo));
    }
    /**
     * 题目-详情
     */
    @PostMapping("/eTopicDetail")
    public R eTopicDetail(@RequestBody ETopic eTopic){
        return R.ok(eTopicService.eTopicDetail(eTopic));
    }
    /**
     * 题目-模板下载
     */
    @PostMapping("/download")
    public R download(@RequestBody DownloadPo downloadPo, HttpServletResponse response){
        return R.ok(eTopicService.download(downloadPo,response));
    }
    /**
     * 题目-模板解析
     */
    @PostMapping("/parse")
    public R parse(@RequestParam("type") Integer type,@RequestParam("file") MultipartFile file) {
        DownloadPo downloadPo = new DownloadPo();
        downloadPo.setType(type);
        return R.ok(eTopicService.parse(downloadPo,file));
    }
    /**
     * 题目-导入
     */
    @PostMapping("/import")
    public R<Boolean> importETopic(List<ETopicAddOrEditPo> eTopicAddOrEditPos){
        // 获取用户信息
        UserCacheData user = ThreadUserContext.getCurrentCacheUser();
        return R.ok(eTopicService.importETopic(eTopicAddOrEditPos));
    }
}

